﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>员工管理</title>
    <!-- Bootstrap -->
    <link href="/CSS/bootstrap3.3.5/css/bootstrap.css" rel="stylesheet">
    <link href="/JqueryPlug/dtGrid/jquery.dtGrid.css" rel="stylesheet">
    <link href="/CSS/font-awesome-4.3.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="/CSS/Base/Button.css" rel="stylesheet">

    <link href="/CSS/Base/BaseClass.css?cssver=4" rel="stylesheet">
    <script src="/Scripts/jquery-1.11.2.min.js"></script>

    <script type="text/javascript" src="/JqueryPlug/layer/layer/layer.js"></script>
    <script src="/CSS/bootstrap3.3.5/js/bootstrap.js"></script>
    <script src="/Scripts/avalon.js"></script>
    <script src="/Scripts/jquery-migrate-1.1.0.min.js"></script>
    <script src="/JqueryPlug/dtGrid/jquery.dtGrid.js"></script>
    <script src="/Scripts/SZHLCommon.js?jsver=5"></script>
    <style>
        .White {
            color: #ffffff;
        }

        .lev1 {
            /*//  margin-left: 10px;*/
        }

        .lev2 {
            padding-left: 40px;
        }

        .list-group .lev2:first-child {
            padding-left: 40px;
            border-top: 1px solid #ddd !important;
        }

        .peples .list-group-item {
            padding-bottom: 5px;
            padding-top: 5px;
        }

        .media-left {
            padding-right: 5px;
        }

        .media-body {
            padding-top: 5px;
        }

        .media-heading {
            margin-top: 8px;
        }

        .list-group-item:hover {
            background-color: #3085DB;
        }


        .isel {
            position: absolute;
            top: 18px;
            right: 10px;
            color: darkgoldenrod;
            font-size: 18px;
        }
    </style>
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript">
        var grid, dtoption;
        //获取主要菜单
        dtoption = {
            lang: 'zh-cn',
            check: false,
            ajaxLoad: false,
            exportFileName: '用户列表',
            columns: [
                { id: 'UserRealName', title: '用户名', type: 'string', columnClass: 'text-center', columnStyle: "width:100px" },
                { id: 'UserName', title: '登录账号', type: 'string', columnClass: 'text-center', columnStyle: "width:100px" },
                { id: 'IsUse', title: '是否启用', type: 'string', columnClass: 'text-center', columnStyle: "width:80px" },
                { id: 'DeptName', title: '所在部门', type: 'string', columnClass: 'text-center', columnStyle: "width:130px" },
                { id: 'DeptCode', title: '所在部门', type: 'string', columnClass: 'text-center', hide: true },
                { id: 'zhiwu', title: '职务', type: 'string', columnClass: 'text-center', columnStyle: "width:130px" },
                {
                    id: 'option', title: '操作', type: 'string', columnClass: 'text-center', columnStyle: "width:200px", resolution: function (value, record, column, grid, dataNo, columnNo) {
                        var content = "";

                        content += '<button class="btn btn-xs btn-default" onclick="model.EditUser(\'' + record.UserName + '\');"><i class="fa fa-edit"></i>  编辑</button>';
                        content += ' ';
                        content += '<button class="btn btn-xs btn-danger" onclick="model.EditIsUse(\'' + record.UserName + '\',\'' + record.IsUse + '\');"><i class="fa fa-edit"></i> ' + (record.IsUse == 'Y' ? '禁用' : '启用') + '</button>';
                        content += ' ';
                        content += '<button class="btn btn-xs btn-danger"  onclick="model.DelUser(\'' + record.UserName + '\',' + dataNo + ')"><i class="fa fa-trash-o"></i>  删除</button>';
                        return content;
                    }
                }
            ],
            gridContainer: 'dtgrid',
            toolbarContainer: 'dtgridTool',
            pageSize: 10,
            pageSizeLimit: [10, 20, 50],
            tools: 'faseQuery',
            onGridComplete: function (grid) {
                var log = '<p>表格加载完成。表格编号：' + grid.option.id + '。</p>';
            }
        };

        var model = avalon.define({
            $id: "YGGL",
            BranchData: [],
            BMLIST: [],//部门列表
            UserListData: [],
            SelDeptItem: {},
            pId: -1,
            GetUserList: function (item, event) {
                if (event) {
                    event.stopPropagation();
                }
                var deptCode = 1;
                if (item != null) {
                    deptCode = item.DeptCode;
                }
                $.getJSON('/API/SZHLAPI.ashx?Action=GETUSERBYCODE', { "P1": deptCode, P2: $("#tbSearch").val() }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        model.UserListData = resultData.Result
                        if (dtoption.datas != undefined) {
                            dtoption.originalDatas = model.UserListData;

                        } else {
                            dtoption.datas = model.UserListData;
                            grid = $.fn.DtGrid.init(dtoption);
                        }
                        grid.load()
                        model.SelDeptItem = item == null ? {} : item;
                    }
                })
            }
            ,
            EditDept: function (item, event) {
                if (event) {
                    event.stopPropagation();
                }
                var deptCode = item.DeptCode
                if ($.trim(deptCode) != "") {
                    parent.ComFunJS.winviewform("/Admin/BranchAdd.html?branchNo=" + deptCode, "修改部门", 788, 400);
                }
            },
            EditUser: function (userName) {
                parent.ComFunJS.winviewform("/Admin/YGGLAdd.html?userName=" + userName, "修改员工", 788, 700);
                model.GetUserList(model.SelDeptItem, null);
            }, DelDept: function (item, event) {
                if (event) {
                    event.stopPropagation();
                }
                if (confirm("确定要删除" + item.DeptName + "么？")) {
                    $.post("/API/SZHLAPI.ashx", { Action: "DELBRANCH", P1: item.DeptCode },
                    function (result) {
                        if ($.trim(result.ErrorMsg) != "") {
                            ComFunJS.winwarning(result.ErrorMsg);
                        } else {
                            // model.BranchData.remove(item);
                            location.reload();
                            model.SelDeptItem = model.BranchData.size() > 0 ? model.BranchData[0] : {};
                        }
                    });
                }
            },
            DelUser: function (userName, rowNumber) {
                if (confirm("确定要删除" + userName + "么？")) {
                    $.post("/API/SZHLAPI.ashx", { Action: "DELUSER", P1: userName },
                    function (result) {
                        if ($.trim(result.ErrorMsg) != "") {
                            ComFunJS.winwarning(result.ErrorMsg);
                        } else {
                            model.UserListData.remove(model.UserListData[rowNumber]);
                            dtoption.originalDatas = model.UserListData;
                            grid.load()
                        }
                    });
                }
            },
            EditIsUse: function (userName, status) {
                $.post("/API/SZHLAPI.ashx", { Action: "UPDATEUSERISUSE", P1: userName, P2: (status == "Y" ? "N" : "Y") },
                  function (result) {
                      if ($.trim(result.ErrorMsg) != "") {
                          ComFunJS.winwarning(result.ErrorMsg);
                      }
                      model.GetUserList(model.SelDeptItem);
                  });
            }, BranchAdd: function (item) {
                var pcode = "";
                var pname = "组织机构";
                if (item.$model.hasOwnProperty("DeptCode")) {
                    pcode = item.$model.DeptCode;
                    pname = item.$model.DeptName;
                }
                parent.ComFunJS.winviewform("/Admin/BranchAdd.html?pcode=" + pcode + "&pname=" + escape(pname), "添加部门", 788, 400);

            }, UserAdd: function () {

                var deptCode = model.SelDeptItem.DeptCode
                if (!deptCode)
                {
                    deptCode = 1;
                }
                if ($.trim(deptCode) != "") {
                    parent.ComFunJS.winviewform("/Admin/YGGLAdd.html?branchNo=" + deptCode, "添加员工", 788, 700);
                }
            }

        });
        avalon.ready(function () {

            $.getJSON('/API/SZHLAPI.ashx?Action=GETBRANCH', { "P1": "1" }, function (resultData) {
                model.BranchData = resultData.Result;
                if (model.BranchData[0].DeptCode) {
                    pId = model.BranchData[0].DeptCode;
                    model.GetUserList(null, null);
                }
            })
            $.getJSON('/API/SZHLAPI.ashx?Action=GETAllBMLIST', { P1: "1" }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    model.BMLIST = resultData.Result;
                    avalon.scan()
                }
            })
        })

    </script>
</head>
<body ms-controller="YGGL" style="background-color:white">
    <div class="container-fluid maindiv" style="margin: 20px" id="dvContent">
        <div class="row">
            <div class="col-xs-3">
                
                <div class="panel panel-default">
                    <!-- Default panel contents -->
                    <div class="panel-heading"><a href="#" ms-click="GetUserList(null, null)">组织机构（全部人员）</a></div>
                    <!-- List group -->
                    <ul class="list-group" ms-each-bm="BMLIST">
                        <li class="list-group-item" ms-class="active:bm.DeptCode==SelDeptItem.DeptCode" ms-click="GetUserList(bm)">
                            {{bm.DeptName}}
                        </li>
                        <ui class="list-group" ms-each-item="bm.xsbm">
                            <li class="list-group-item lev2" ms-class="active:item.DeptCode==SelDeptItem.DeptCode" ms-click="GetUserList(item)"> {{item.DeptName}}</li>
                        </ui>
                    </ul>
                </div>
            </div>
            <div class="col-xs-9">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="row">
                            <div class="col-xs-7">
                                {{SelDeptItem.DeptName?SelDeptItem.DeptName:"组织机构"}}
                                <a href="#" ms-click="BranchAdd(SelDeptItem)" style=" line-height: 15px; margin-left:8px; ">添加子部门</a>
                                <a href="#" id="btADDGL" ms-click="UserAdd()" style="margin-left:10px">添加员工</a>
                                <a href="#" ms-click="EditDept(SelDeptItem,event)" style=" line-height: 15px; margin-left:8px; ">修改</a>
                                <a href="#" ms-click="DelDept(SelDeptItem,event)" ms-if="SelDeptItem.userCount<=0" style=" line-height: 15px; margin-left:8px; ">删除</a>
                            </div>
                            <div class="col-xs-5">
                                <div class="input-group">
                                    <div class="input-group-addon">搜索关键字</div>
                                    <input id="tbSearch" class="form-control" type="text" placeholder="姓名,部门,手机号..." />
                                    <span class="input-group-btn">
                                        <button class="btn btn-info " ms-click="GetUserList(SelDeptItem)">查询</button>
                                    </span>
                                </div>
                            </div>
                        </div>



                    </div>
                    <div class="panel-body">

                        <div id="dtgrid" style="margin-top:20px"></div>
                        <div id="dtgridTool" class="dt-grid-toolbar-container"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>